﻿using System;
using System.Collections.Generic;
using System.Text;
using RemoteBank.Interface;
using RemoteBank.Entity;
using System.Data;
using System.Data.SqlClient;
using RemoteBank.DAL;
namespace RemoteBank.BLL
{
    class AccountBLL : InterfaceAccount
    {



        #region InterfaceAccount Members

        public List<Account> GetAllAccount(int UserID)
        {
            
            List<Account> listAcc = new List<Account>();

            RemoteBankDAL dal = new RemoteBankDAL();
            SqlDataReader reader;
            SqlParameter para;
            List<SqlParameter> ListPara = new List<SqlParameter>();

            para = new SqlParameter("@UserID", SqlDbType.Int);
            para.Value = UserID;
            ListPara.Add(para);

            reader = dal.ExecuteQuerry_GetDataReader("getAccountByUserID", ListPara);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Account acc = new Account();
                    acc.AccountID = Convert.ToInt32(reader[0].ToString());
                    acc.UserID = Convert.ToInt32(reader[1].ToString());
                    acc.AccountName = reader[2].ToString();
                    acc.AccountType = Convert.ToInt32(reader[3].ToString());
                    acc.Balance = Convert.ToDouble(reader[4].ToString());
                    acc.Password = reader[5].ToString();
                    acc.MoneyType = Convert.ToInt32(reader[6].ToString());
                    listAcc.Add(acc);

                }
                return listAcc;
            }
            else
            {
                return null;
            }
        }

        #endregion
    }
}
